.class public Lcom/hyphenate/chat/adapter/EMARHttpAPI;
.super Ljava/lang/Object;


# static fields
.field public static HIGH_SPEED_DOWNLOAD_BUF_SIZE:I = 0x0

.field public static Method_DELETE:Ljava/lang/String; = null

.field public static Method_GET:Ljava/lang/String; = null

.field public static Method_POST:Ljava/lang/String; = null

.field public static Method_PUT:Ljava/lang/String; = null

.field public static REQUEST_AUTHENTICATION_FAILED:I = 0x0

.field public static REQUEST_FAILED_CODE:I = 0x0

.field public static final TAG:Ljava/lang/String; = "EMARHttpAPI"


# instance fields
.field final tokenRetrieved:Z


# direct methods
.method static constructor <clinit>()V
    .locals 1

    const-string/jumbo v0, "GET"

    sput-object v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_GET:Ljava/lang/String;

    const-string/jumbo v0, "POST"

    sput-object v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_POST:Ljava/lang/String;

    const-string/jumbo v0, "PUT"

    sput-object v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_PUT:Ljava/lang/String;

    const-string/jumbo v0, "DELETE"

    sput-object v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_DELETE:Ljava/lang/String;

    const/16 v0, 0x198

    sput v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->REQUEST_FAILED_CODE:I

    const/16 v0, 0x190

    sput v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->REQUEST_AUTHENTICATION_FAILED:I

    const/16 v0, 0x7800

    sput v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->HIGH_SPEED_DOWNLOAD_BUF_SIZE:I

    return-void
.end method

.method public constructor <init>()V
    .locals 1

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->tokenRetrieved:Z

    return-void
.end method

.method private static _httpExecute(Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;)Lorg/apache/http/HttpResponse;
    .locals 5

    const/4 v0, 0x0

    invoke-static {p1}, Lcom/hyphenate/cloud/HttpClientConfig;->getTimeout(Ljava/util/Map;)I

    move-result v1

    invoke-static {v1}, Lcom/hyphenate/cloud/HttpClientConfig;->getDefaultHttpClient(I)Lorg/apache/http/impl/client/DefaultHttpClient;

    move-result-object v3

    sget-object v1, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_POST:Ljava/lang/String;

    invoke-virtual {p3, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_0

    new-instance v1, Lorg/apache/http/client/methods/HttpPost;

    invoke-direct {v1, p0}, Lorg/apache/http/client/methods/HttpPost;-><init>(Ljava/lang/String;)V

    new-instance v2, Lorg/apache/http/entity/StringEntity;

    const-string/jumbo v4, "UTF-8"

    invoke-direct {v2, p2, v4}, Lorg/apache/http/entity/StringEntity;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v1, v2}, Lorg/apache/http/client/methods/HttpPost;->setEntity(Lorg/apache/http/HttpEntity;)V

    move-object v2, v1

    :goto_0
    if-eqz v2, :cond_4

    if-eqz p1, :cond_3

    invoke-interface {p1}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v0

    invoke-interface {v0}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v4

    :goto_1
    invoke-interface {v4}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_3

    invoke-interface {v4}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    invoke-virtual {v2, v1, v0}, Lorg/apache/http/client/methods/HttpRequestBase;->setHeader(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_1

    :cond_0
    sget-object v1, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_PUT:Ljava/lang/String;

    invoke-virtual {p3, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_1

    new-instance v1, Lorg/apache/http/client/methods/HttpPut;

    invoke-direct {v1, p0}, Lorg/apache/http/client/methods/HttpPut;-><init>(Ljava/lang/String;)V

    new-instance v2, Lorg/apache/http/entity/StringEntity;

    const-string/jumbo v4, "UTF-8"

    invoke-direct {v2, p2, v4}, Lorg/apache/http/entity/StringEntity;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v1, v2}, Lorg/apache/http/client/methods/HttpPut;->setEntity(Lorg/apache/http/HttpEntity;)V

    move-object v2, v1

    goto :goto_0

    :cond_1
    sget-object v1, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_GET:Ljava/lang/String;

    invoke-virtual {p3, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_2

    new-instance v1, Lorg/apache/http/client/methods/HttpGet;

    invoke-direct {v1, p0}, Lorg/apache/http/client/methods/HttpGet;-><init>(Ljava/lang/String;)V

    move-object v2, v1

    goto :goto_0

    :cond_2
    sget-object v1, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->Method_DELETE:Ljava/lang/String;

    invoke-virtual {p3, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_5

    new-instance v1, Lorg/apache/http/client/methods/HttpDelete;

    invoke-direct {v1, p0}, Lorg/apache/http/client/methods/HttpDelete;-><init>(Ljava/lang/String;)V

    move-object v2, v1

    goto :goto_0

    :cond_3
    invoke-interface {v3, v2}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v0

    :cond_4
    return-object v0

    :cond_5
    move-object v2, v0

    goto :goto_0
.end method

.method public static download(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lcom/hyphenate/chat/adapter/EMARHttpCallback;)I
    .locals 6

    sget v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->REQUEST_FAILED_CODE:I

    if-eqz p0, :cond_0

    invoke-virtual {p0}, Ljava/lang/String;->length()I

    move-result v1

    if-gtz v1, :cond_2

    :cond_0
    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "invalid remoteUrl"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    :cond_1
    :goto_0
    return v0

    :cond_2
    invoke-static {p0}, Lcom/hyphenate/cloud/HttpClientConfig;->getFileRemoteUrl(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->processUrl(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    const-string/jumbo v2, "EMARHttpAPI"

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v4, "download file: remote url : "

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string/jumbo v4, " , local file : "

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v2, v3}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    new-instance v2, Ljava/io/File;

    invoke-direct {v2, p1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    const-string/jumbo v3, "EMARHttpAPI"

    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v5, "local exists:"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v2}, Ljava/io/File;->exists()Z

    move-result v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Z)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v3, v4}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v2}, Ljava/io/File;->getParentFile()Ljava/io/File;

    move-result-object v3

    invoke-virtual {v3}, Ljava/io/File;->exists()Z

    move-result v3

    if-nez v3, :cond_3

    invoke-virtual {v2}, Ljava/io/File;->getParentFile()Ljava/io/File;

    move-result-object v2

    invoke-virtual {v2}, Ljava/io/File;->mkdirs()Z

    :cond_3
    invoke-static {p2}, Lcom/hyphenate/cloud/HttpClientConfig;->getTimeout(Ljava/util/Map;)I

    move-result v2

    invoke-static {v2}, Lcom/hyphenate/cloud/HttpClientConfig;->getDefaultHttpClient(I)Lorg/apache/http/impl/client/DefaultHttpClient;

    move-result-object v2

    :try_start_0
    new-instance v3, Lorg/apache/http/client/methods/HttpGet;

    invoke-direct {v3, v1}, Lorg/apache/http/client/methods/HttpGet;-><init>(Ljava/lang/String;)V

    invoke-static {v3, p2}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->processHeaders(Lorg/apache/http/client/methods/HttpGet;Ljava/util/Map;)V

    invoke-virtual {v2, v3}, Lorg/apache/http/impl/client/DefaultHttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v1

    invoke-interface {v1}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v2

    invoke-interface {v2}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v0

    sparse-switch v0, :sswitch_data_0

    const-string/jumbo v1, "EMARHttpAPI"

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v3, "error response code is :"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto/16 :goto_0

    :catch_0
    move-exception v1

    move-object v2, v1

    move v1, v0

    invoke-virtual {v2}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v0

    if-nez v0, :cond_4

    invoke-virtual {v2}, Ljava/lang/Exception;->toString()Ljava/lang/String;

    move-result-object v0

    if-nez v0, :cond_4

    const-string/jumbo v0, "failed to download file"

    :cond_4
    const-string/jumbo v2, "EMARHttpAPI"

    invoke-static {v2, v0}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    move v0, v1

    goto/16 :goto_0

    :sswitch_0
    :try_start_1
    invoke-static {v1, p3, p1}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->onDownloadCompleted(Lorg/apache/http/HttpResponse;Lcom/hyphenate/chat/adapter/EMARHttpCallback;Ljava/lang/String;)J

    move-result-wide v2

    const-wide/16 v4, 0x0

    cmp-long v1, v2, v4

    if-gtz v1, :cond_5

    sget v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->REQUEST_FAILED_CODE:I

    goto/16 :goto_0

    :cond_5
    if-eqz p3, :cond_1

    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "download successfully"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto/16 :goto_0

    :sswitch_1
    invoke-static {}, Lcom/hyphenate/cloud/EMHttpClient;->getInstance()Lcom/hyphenate/cloud/EMHttpClient;

    move-result-object v1

    invoke-virtual {v1}, Lcom/hyphenate/cloud/EMHttpClient;->chatConfig()Lcom/hyphenate/chat/a/b;

    move-result-object v1

    invoke-virtual {v1}, Lcom/hyphenate/chat/a/b;->o()J

    move-result-wide v2

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v4

    sub-long v2, v4, v2

    const-wide/32 v4, 0x927c0

    cmp-long v1, v2, v4

    if-gtz v1, :cond_1

    if-eqz p3, :cond_1

    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "unauthorized file"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto/16 :goto_0

    :sswitch_data_0
    .sparse-switch
        0xc8 -> :sswitch_0
        0x191 -> :sswitch_1
    .end sparse-switch
.end method

.method private static getMimeType(Ljava/io/File;)Ljava/lang/String;
    .locals 2

    invoke-virtual {p0}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v0

    const-string/jumbo v1, ".3gp"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_0

    const-string/jumbo v1, ".amr"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v1

    if-eqz v1, :cond_1

    :cond_0
    const-string/jumbo v0, "audio/3gp"

    :goto_0
    return-object v0

    :cond_1
    const-string/jumbo v1, ".jpe"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_2

    const-string/jumbo v1, ".jpeg"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_2

    const-string/jumbo v1, ".jpg"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v1

    if-eqz v1, :cond_3

    :cond_2
    const-string/jumbo v0, "image/jpeg"

    goto :goto_0

    :cond_3
    const-string/jumbo v1, ".amr"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v1

    if-eqz v1, :cond_4

    const-string/jumbo v0, "audio/amr"

    goto :goto_0

    :cond_4
    const-string/jumbo v1, ".mp4"

    invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_5

    const-string/jumbo v0, "video/mp4"

    goto :goto_0

    :cond_5
    const-string/jumbo v0, "image/png"

    goto :goto_0
.end method

.method private static getResponseContent(Lorg/apache/http/HttpResponse;)Lorg/apache/http/util/ByteArrayBuffer;
    .locals 8

    const/4 v1, 0x0

    sget v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->HIGH_SPEED_DOWNLOAD_BUF_SIZE:I

    new-array v2, v0, [B

    new-instance v3, Lorg/apache/http/util/ByteArrayBuffer;

    invoke-direct {v3, v0}, Lorg/apache/http/util/ByteArrayBuffer;-><init>(I)V

    :try_start_0
    invoke-interface {p0}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v0

    invoke-interface {v0}, Lorg/apache/http/HttpEntity;->getContent()Ljava/io/InputStream;

    move-result-object v1

    :goto_0
    invoke-virtual {v1, v2}, Ljava/io/InputStream;->read([B)I

    move-result v0

    int-to-long v4, v0

    const-wide/16 v6, -0x1

    cmp-long v0, v4, v6

    if-eqz v0, :cond_0

    const/4 v0, 0x0

    long-to-int v4, v4

    invoke-virtual {v3, v2, v0, v4}, Lorg/apache/http/util/ByteArrayBuffer;->append([BII)V
    :try_end_0
    .catch Ljava/lang/IllegalStateException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    goto :goto_0

    :catch_0
    move-exception v0

    :try_start_1
    invoke-virtual {v0}, Ljava/lang/IllegalStateException;->printStackTrace()V

    throw v0
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    :catchall_0
    move-exception v0

    invoke-virtual {v1}, Ljava/io/InputStream;->close()V

    throw v0

    :cond_0
    invoke-virtual {v1}, Ljava/io/InputStream;->close()V

    return-object v3

    :catch_1
    move-exception v0

    :try_start_2
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V

    throw v0
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0
.end method

.method public static httpExecute(Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/StringBuilder;)I
    .locals 6

    sget v0, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->REQUEST_FAILED_CODE:I

    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "httpExecute"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    :try_start_0
    invoke-static {p0, p1, p2, p3}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->_httpExecute(Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;)Lorg/apache/http/HttpResponse;

    move-result-object v1

    invoke-static {v1}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->getResponseContent(Lorg/apache/http/HttpResponse;)Lorg/apache/http/util/ByteArrayBuffer;

    move-result-object v2

    const/4 v3, 0x0

    invoke-virtual {p4}, Ljava/lang/StringBuilder;->length()I

    move-result v4

    invoke-virtual {p4, v3, v4}, Ljava/lang/StringBuilder;->delete(II)Ljava/lang/StringBuilder;

    new-instance v3, Ljava/lang/String;

    invoke-virtual {v2}, Lorg/apache/http/util/ByteArrayBuffer;->buffer()[B

    move-result-object v4

    const/4 v5, 0x0

    invoke-virtual {v2}, Lorg/apache/http/util/ByteArrayBuffer;->length()I

    move-result v2

    invoke-direct {v3, v4, v5, v2}, Ljava/lang/String;-><init>([BII)V

    invoke-virtual {p4, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-interface {v1}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v1

    invoke-interface {v1}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v0

    const-string/jumbo v1, "EMARHttpAPI"

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v3, "httpExecute code: "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_0
    .catch Lorg/apache/http/conn/ConnectTimeoutException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    :goto_0
    return v0

    :catch_0
    move-exception v1

    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "ConnectTimeoutException"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    :goto_1
    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "can\'t catch exceptions"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_0

    :catch_1
    move-exception v1

    const-string/jumbo v2, "EMARHttpAPI"

    invoke-virtual {v1}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v3

    invoke-static {v2, v3}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v1}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_1
.end method

.method private static onDownloadCompleted(Lorg/apache/http/HttpResponse;Lcom/hyphenate/chat/adapter/EMARHttpCallback;Ljava/lang/String;)J
    .locals 24

    invoke-interface/range {p0 .. p0}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v6

    if-nez v6, :cond_0

    const-wide/16 v6, 0x0

    :goto_0
    return-wide v6

    :cond_0
    const/4 v8, 0x0

    invoke-interface {v6}, Lorg/apache/http/HttpEntity;->getContentLength()J

    move-result-wide v10

    :try_start_0
    invoke-interface {v6}, Lorg/apache/http/HttpEntity;->getContent()Ljava/io/InputStream;
    :try_end_0
    .catch Ljava/lang/IllegalStateException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_2

    move-result-object v12

    new-instance v13, Ljava/io/File;

    move-object/from16 v0, p2

    invoke-direct {v13, v0}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    :try_start_1
    new-instance v14, Ljava/io/FileOutputStream;

    invoke-direct {v14, v13}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V
    :try_end_1
    .catch Ljava/io/FileNotFoundException; {:try_start_1 .. :try_end_1} :catch_3

    sget v6, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->HIGH_SPEED_DOWNLOAD_BUF_SIZE:I

    new-array v15, v6, [B

    const-wide/16 v6, 0x0

    move-wide/from16 v22, v6

    move v6, v8

    move-wide/from16 v8, v22

    :goto_1
    :try_start_2
    invoke-virtual {v12, v15}, Ljava/io/InputStream;->read([B)I

    move-result v16

    const/4 v7, -0x1

    move/from16 v0, v16

    if-eq v0, v7, :cond_4

    move/from16 v0, v16

    int-to-long v0, v0

    move-wide/from16 v18, v0

    add-long v8, v8, v18

    const-wide/16 v18, 0x64

    mul-long v18, v18, v8

    div-long v18, v18, v10

    move-wide/from16 v0, v18

    long-to-int v7, v0

    const-string/jumbo v17, "EMARHttpAPI"

    new-instance v18, Ljava/lang/StringBuilder;

    invoke-direct/range {v18 .. v18}, Ljava/lang/StringBuilder;-><init>()V

    move-object/from16 v0, v18

    invoke-virtual {v0, v7}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v18

    const-string/jumbo v19, ""

    invoke-virtual/range {v18 .. v19}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v18

    invoke-virtual/range {v18 .. v18}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v18

    invoke-static/range {v17 .. v18}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    const/16 v17, 0x64

    move/from16 v0, v17

    if-eq v7, v0, :cond_1

    add-int/lit8 v17, v6, 0x5

    move/from16 v0, v17

    if-le v7, v0, :cond_3

    :cond_1
    if-eqz p1, :cond_2

    long-to-double v0, v10

    move-wide/from16 v18, v0

    long-to-double v0, v8

    move-wide/from16 v20, v0

    move-object/from16 v0, p1

    move-wide/from16 v1, v18

    move-wide/from16 v3, v20

    invoke-virtual {v0, v1, v2, v3, v4}, Lcom/hyphenate/chat/adapter/EMARHttpCallback;->onProgress(DD)V

    :cond_2
    move v6, v7

    :cond_3
    const/4 v7, 0x0

    move/from16 v0, v16

    invoke-virtual {v14, v15, v7, v0}, Ljava/io/OutputStream;->write([BII)V
    :try_end_2
    .catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_0
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    goto :goto_1

    :catch_0
    move-exception v6

    :try_start_3
    invoke-virtual {v6}, Ljava/io/IOException;->printStackTrace()V

    throw v6
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    :catchall_0
    move-exception v6

    invoke-virtual {v14}, Ljava/io/OutputStream;->close()V

    invoke-virtual {v12}, Ljava/io/InputStream;->close()V

    throw v6

    :catch_1
    move-exception v6

    invoke-virtual {v6}, Ljava/lang/IllegalStateException;->printStackTrace()V

    throw v6

    :catch_2
    move-exception v6

    invoke-virtual {v6}, Ljava/io/IOException;->printStackTrace()V

    throw v6

    :catch_3
    move-exception v6

    invoke-virtual {v6}, Ljava/io/FileNotFoundException;->printStackTrace()V

    invoke-virtual {v12}, Ljava/io/InputStream;->close()V

    throw v6

    :cond_4
    :try_start_4
    invoke-virtual {v13}, Ljava/io/File;->length()J
    :try_end_4
    .catch Ljava/io/IOException; {:try_start_4 .. :try_end_4} :catch_0
    .catchall {:try_start_4 .. :try_end_4} :catchall_0

    move-result-wide v6

    invoke-virtual {v14}, Ljava/io/OutputStream;->close()V

    invoke-virtual {v12}, Ljava/io/InputStream;->close()V

    goto/16 :goto_0
.end method

.method private static processHeaders(Lorg/apache/http/client/methods/HttpGet;Ljava/util/Map;)V
    .locals 4

    const-string/jumbo v0, "Authorization"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v2, "Bearer "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-static {}, Lcom/hyphenate/chat/EMClient;->getInstance()Lcom/hyphenate/chat/EMClient;

    move-result-object v2

    invoke-virtual {v2}, Lcom/hyphenate/chat/EMClient;->getChatConfig()Lcom/hyphenate/chat/EMChatConfig;

    move-result-object v2

    invoke-virtual {v2}, Lcom/hyphenate/chat/EMChatConfig;->getAccessToken()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {p0, v0, v1}, Lorg/apache/http/client/methods/HttpGet;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    const-string/jumbo v0, "Accept"

    const-string/jumbo v1, "application/octet-stream"

    invoke-virtual {p0, v0, v1}, Lorg/apache/http/client/methods/HttpGet;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    if-eqz p1, :cond_1

    invoke-interface {p1}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v0

    invoke-interface {v0}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v2

    :cond_0
    :goto_0
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_1

    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    const-string/jumbo v3, "Authorization"

    invoke-virtual {v1, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-nez v1, :cond_0

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    const-string/jumbo v3, "Accept"

    invoke-virtual {v1, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-nez v1, :cond_0

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    invoke-virtual {p0, v1, v0}, Lorg/apache/http/client/methods/HttpGet;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_0

    :cond_1
    return-void
.end method

.method private static processUrl(Ljava/lang/String;)Ljava/lang/String;
    .locals 2

    const-string/jumbo v0, "+"

    invoke-virtual {p0, v0}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v0

    if-eqz v0, :cond_0

    const-string/jumbo v0, "\\+"

    const-string/jumbo v1, "%2B"

    invoke-virtual {p0, v0, v1}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    :cond_0
    const-string/jumbo v0, "#"

    invoke-virtual {p0, v0}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v0

    if-eqz v0, :cond_1

    const-string/jumbo v0, "#"

    const-string/jumbo v1, "%23"

    invoke-virtual {p0, v0, v1}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    :cond_1
    return-object p0
.end method

.method public static upload(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/lang/StringBuilder;Lcom/hyphenate/chat/adapter/EMARHttpCallback;)I
    .locals 8

    invoke-static {}, Lcom/hyphenate/chat/EMClient;->getInstance()Lcom/hyphenate/chat/EMClient;

    move-result-object v0

    invoke-virtual {v0}, Lcom/hyphenate/chat/EMClient;->getChatConfig()Lcom/hyphenate/chat/EMChatConfig;

    move-result-object v0

    invoke-virtual {v0}, Lcom/hyphenate/chat/EMChatConfig;->getAppKey()Ljava/lang/String;

    move-result-object v0

    invoke-static {}, Lcom/hyphenate/chat/EMClient;->getInstance()Lcom/hyphenate/chat/EMClient;

    move-result-object v1

    invoke-virtual {v1}, Lcom/hyphenate/chat/EMClient;->getCurrentUser()Ljava/lang/String;

    move-result-object v1

    new-instance v3, Ljava/io/File;

    invoke-direct {v3, p0}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    sget v2, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->REQUEST_FAILED_CODE:I

    const-string/jumbo v4, "EMARHttpAPI"

    const-string/jumbo v5, "upload"

    invoke-static {v4, v5}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    new-instance v4, Lcom/hyphenate/cloud/CustomMultiPartEntity;

    const/4 v5, 0x0

    invoke-direct {v4, v5}, Lcom/hyphenate/cloud/CustomMultiPartEntity;-><init>(Lcom/hyphenate/cloud/CustomMultiPartEntity$ProgressListener;)V

    if-eqz v0, :cond_0

    :try_start_0
    const-string/jumbo v5, "app"

    new-instance v6, Linternal/org/apache/http/entity/mime/content/StringBody;

    invoke-direct {v6, v0}, Linternal/org/apache/http/entity/mime/content/StringBody;-><init>(Ljava/lang/String;)V

    invoke-virtual {v4, v5, v6}, Lcom/hyphenate/cloud/CustomMultiPartEntity;->addPart(Ljava/lang/String;Linternal/org/apache/http/entity/mime/content/ContentBody;)V

    :cond_0
    if-eqz v1, :cond_1

    const-string/jumbo v0, "id"

    new-instance v5, Linternal/org/apache/http/entity/mime/content/StringBody;

    invoke-direct {v5, v1}, Linternal/org/apache/http/entity/mime/content/StringBody;-><init>(Ljava/lang/String;)V

    invoke-virtual {v4, v0, v5}, Lcom/hyphenate/cloud/CustomMultiPartEntity;->addPart(Ljava/lang/String;Linternal/org/apache/http/entity/mime/content/ContentBody;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :cond_1
    invoke-static {v3}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->getMimeType(Ljava/io/File;)Ljava/lang/String;

    move-result-object v1

    const-string/jumbo v0, "/"

    invoke-virtual {p0, v0}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I

    move-result v0

    if-lez v0, :cond_3

    const-string/jumbo v0, "/"

    invoke-virtual {p0, v0}, Ljava/lang/String;->lastIndexOf(Ljava/lang/String;)I

    move-result v0

    invoke-virtual {p1, v0}, Ljava/lang/String;->substring(I)Ljava/lang/String;

    move-result-object v0

    :goto_0
    const-string/jumbo v5, "file"

    new-instance v6, Linternal/org/apache/http/entity/mime/content/FileBody;

    const-string/jumbo v7, "UTF-8"

    invoke-direct {v6, v3, v0, v1, v7}, Linternal/org/apache/http/entity/mime/content/FileBody;-><init>(Ljava/io/File;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v4, v5, v6}, Lcom/hyphenate/cloud/CustomMultiPartEntity;->addPart(Ljava/lang/String;Linternal/org/apache/http/entity/mime/content/ContentBody;)V

    invoke-virtual {v4}, Lcom/hyphenate/cloud/CustomMultiPartEntity;->getContentLength()J

    move-result-wide v0

    new-instance v3, Lcom/hyphenate/chat/adapter/EMARHttpAPI$1;

    invoke-direct {v3, v0, v1, p4}, Lcom/hyphenate/chat/adapter/EMARHttpAPI$1;-><init>(JLcom/hyphenate/chat/adapter/EMARHttpCallback;)V

    invoke-virtual {v4, v3}, Lcom/hyphenate/cloud/CustomMultiPartEntity;->setListener(Lcom/hyphenate/cloud/CustomMultiPartEntity$ProgressListener;)V

    invoke-static {p1}, Lcom/hyphenate/cloud/HttpClientConfig;->getFileRemoteUrl(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    new-instance v3, Lorg/apache/http/client/methods/HttpPost;

    invoke-direct {v3, v0}, Lorg/apache/http/client/methods/HttpPost;-><init>(Ljava/lang/String;)V

    invoke-virtual {v3, v4}, Lorg/apache/http/client/methods/HttpPost;->setEntity(Lorg/apache/http/HttpEntity;)V

    if-eqz p2, :cond_2

    invoke-interface {p2}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v0

    invoke-interface {v0}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v4

    :goto_1
    invoke-interface {v4}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_2

    invoke-interface {v4}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    invoke-virtual {v3, v1, v0}, Lorg/apache/http/client/methods/HttpPost;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_1

    :catch_0
    move-exception v0

    const-string/jumbo v1, "EMARHttpAPI"

    invoke-virtual {v0}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v0

    invoke-static {v1, v0}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    move v0, v2

    :goto_2
    return v0

    :cond_2
    invoke-static {}, Lcom/hyphenate/cloud/HttpClientConfig;->getDefaultHttpClient()Lorg/apache/http/impl/client/DefaultHttpClient;

    move-result-object v0

    :try_start_1
    invoke-virtual {v0, v3}, Lorg/apache/http/impl/client/DefaultHttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v1

    invoke-interface {v1}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v0

    invoke-interface {v0}, Lorg/apache/http/StatusLine;->getStatusCode()I
    :try_end_1
    .catch Lorg/apache/http/conn/ConnectTimeoutException; {:try_start_1 .. :try_end_1} :catch_5
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_3

    move-result v0

    packed-switch v0, :pswitch_data_0

    goto :goto_2

    :pswitch_0
    :try_start_2
    invoke-static {v1}, Lcom/hyphenate/chat/adapter/EMARHttpAPI;->getResponseContent(Lorg/apache/http/HttpResponse;)Lorg/apache/http/util/ByteArrayBuffer;

    move-result-object v1

    const-string/jumbo v2, "EMARHttpAPI"

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v4, "getBackupInfo result:"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    new-instance v4, Ljava/lang/String;

    invoke-virtual {v1}, Lorg/apache/http/util/ByteArrayBuffer;->buffer()[B

    move-result-object v5

    const/4 v6, 0x0

    invoke-virtual {v1}, Lorg/apache/http/util/ByteArrayBuffer;->length()I

    move-result v7

    invoke-direct {v4, v5, v6, v7}, Ljava/lang/String;-><init>([BII)V

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v2, v3}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    new-instance v2, Ljava/lang/String;

    invoke-virtual {v1}, Lorg/apache/http/util/ByteArrayBuffer;->buffer()[B

    move-result-object v3

    const/4 v4, 0x0

    invoke-virtual {v1}, Lorg/apache/http/util/ByteArrayBuffer;->length()I

    move-result v1

    invoke-direct {v2, v3, v4, v1}, Ljava/lang/String;-><init>([BII)V

    invoke-virtual {p3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_1
    .catch Lorg/apache/http/conn/ConnectTimeoutException; {:try_start_2 .. :try_end_2} :catch_2

    goto :goto_2

    :catch_1
    move-exception v1

    :try_start_3
    const-string/jumbo v1, "sendImageMessage"

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v3, "json parse exception remotefilepath:"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_3
    .catch Lorg/apache/http/conn/ConnectTimeoutException; {:try_start_3 .. :try_end_3} :catch_2
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_4

    goto :goto_2

    :catch_2
    move-exception v1

    :goto_3
    const-string/jumbo v1, "EMARHttpAPI"

    const-string/jumbo v2, "ConnectTimeoutException"

    invoke-static {v1, v2}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_2

    :catch_3
    move-exception v0

    move-object v1, v0

    move v0, v2

    :goto_4
    const-string/jumbo v2, "EMARHttpAPI"

    invoke-virtual {v1}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v1

    invoke-static {v2, v1}, Lcom/hyphenate/util/EMLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto/16 :goto_2

    :catch_4
    move-exception v1

    goto :goto_4

    :catch_5
    move-exception v0

    move v0, v2

    goto :goto_3

    :cond_3
    move-object v0, p1

    goto/16 :goto_0

    nop

    :pswitch_data_0
    .packed-switch 0xc8
        :pswitch_0
    .end packed-switch
.end method
